﻿Imports System.Data.SqlClient
Public Class SuaMonHoc

    Private _str As String
    Dim SuaMonHoc As String

    Sub New(ByVal str As String)
        ' TODO: Complete member initialization 
        _str = str
    End Sub

    Private Sub btnSua_Click(sender As System.Object, e As System.EventArgs) Handles btnSua.Click
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        Dim SoTrinh As Integer
        SoTrinh = Convert.ToInt16(txtSoTrinh.Text)
        cmd.CommandText = "UPDATE MonHoc SET TenMonHoc='" + txtTenMonHoc.Text + "',SoTrinh=" + SoTrinh + ",GiangVien='" + txtGiangVien.Text + "'WHERE MonHoc_ID='" + MaMonHoc + "'"
        Dim result As DialogResult
        result = MessageBox.Show("BẠN CÓ MUỐN THAY ĐỔI THÔNG TIN KHÔNG?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = DialogResult.Yes Then
            cmd.ExecuteNonQuery()
            con.Close()
            MessageBox.Show("CẬP NHẬT DỮ LIỆU THÀNH CÔNG", "THÔNG BÁO")
            Me.Close()
            Dim frm As DanhSachMonHoc = New DanhSachMonHoc()
            frm.Show()
        End If
    End Sub

    Private Sub button1_Click(sender As System.Object, e As System.EventArgs) Handles button1.Click
        Me.Close()
        Dim frm As DanhSachMonHoc = New DanhSachMonHoc()
        frm.Show()
    End Sub

    Private Sub SuaMonHoc_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "SELECT * FROM MonHoc WHERE MonHoc_ID='" + SuaMonHoc + "'"
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        Me.txtMaMonHoc.Text = td.Rows(0)(0).ToString()
        Me.txtTenMonHoc.Text = td.Rows(0)(1).ToString()
        Me.txtSoTrinh.Text = td.Rows(0)(2).ToString()
        Me.txtGiangVien.Text = td.Rows(0)(3).ToString()
        con.Close()

    End Sub

    Private Function MaMonHoc() As Double
        Throw New NotImplementedException
    End Function

End Class